﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;


namespace BE.Web.Betfair.Interface
{
    /// <summary>
    /// Session for retrieving data
    /// </summary>
    [DebuggerDisplay("User: {UserId} - Token {Token}")]
    public sealed class Session
    {
        /// <summary>
        /// Indicates wether this session is authenticated
        /// </summary>
        public bool Authenticated { get; set; }

        /// <summary>
        /// Gets or sets the user id.
        /// </summary>
        /// <value>The user id.</value>
        public string UserId { get; private set; }

        /// <summary>
        /// Gets or sets the token.
        /// </summary>
        /// <value>The token.</value>
        public string Token { get; set; }

        /// <summary>
        /// Gets or sets the created.
        /// </summary>
        /// <value>The created.</value>
        public DateTime Created { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="Session"/> class.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="sessionToken">The session token.</param>
        public Session(string userId, string sessionToken)
        {
            this.UserId = userId;
            this.Token = sessionToken;
            this.Created = DateTime.Now; 
        }

        
        #region overrides
        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode()
        {
            return this.Token.GetHashCode();
        }

        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        /// 	<c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            bool same = false;

            if (obj is Session)
            {
                if (Object.ReferenceEquals(obj, this))
                {
                    same = true;
                }
                else
                {
                    same = ((Session)obj).Token == this.Token;
                }
            }
            return same;
        }

        #endregion
    }
}
